package com.fy.aop;

import com.fy.entity.Log;
import com.fy.service.ILogService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@Aspect
@Component
public class MyLog {
    @Autowired
    HttpServletRequest request;
    @Autowired
    ILogService logService;
    @Before("@annotation(com.fy.aop.LogAnn)")
    public void log(JoinPoint joinPoint) throws InterruptedException {
        System.out.println("前置通知开始-------------------");
        Log log = new Log();
        log.setIp(request.getRemoteAddr());
        log.setInsertdate(LocalDate.now());
        logService.saveAop(log);
        System.out.println("前置通知结束--------------------");
    }
}
